package com.localjoycommunity.cpdj.project.system.mapper;

/**
 * @author: aqie
 * @create: 2020-11-29 16:57
 **/

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.localjoycommunity.cpdj.project.system.domain.User;
import com.localjoycommunity.cpdj.project.system.domain.UserWish;
import com.localjoycommunity.cpdj.project.system.domain.vo.UserWishActivityListVo;
import com.localjoycommunity.cpdj.project.system.domain.vo.UserWishHistoryVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

/**
 * 用户心愿Mapper接口
 *
 * @author leepandar
 * @date 2020-11-16
 */
public interface UserWishMapper extends BaseMapper<UserWish> {
    /**
     * 查询用户心愿
     *
     * @param id 用户心愿ID
     * @return 用户心愿
     */
    public UserWish selectUserWishById(Long id);

    /**
     * 查询用户心愿列表
     *
     * @param userWish 用户心愿
     * @return 用户心愿集合
     */
    public List<UserWish> selectUserWishList(UserWish userWish);

    /**
     * 新增用户心愿
     *
     * @param userWish 用户心愿
     * @return 结果
     */
    public int insertUserWish(UserWish userWish);

    /**
     * 修改用户心愿
     *
     * @param userWish 用户心愿
     * @return 结果
     */
    public int updateUserWish(UserWish userWish);

    /**
     * 删除用户心愿
     *
     * @param id 用户心愿ID
     * @return 结果
     */
    public int deleteUserWishById(Long id);

    /**
     * 批量删除用户心愿
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteUserWishByIds(Long[] ids);

    @Select("SELECT uw.id,uw.create_time,uw.complate_time,uw.state_code,u.name,wl.title FROM user_wish as uw left join `user` as u on uw.user_id=u.id left join wish_list as wl on uw.wish_id=wl.id;")
    List<UserWishHistoryVo> selectUserWishHistory();

    @Select("select state_code from user_wish where  wish_id=#{wishId};")
    Optional<Integer> isApplyWish(Long wishId);

    @Select("SELECT aw.id,aw.title,aw.end_time,aw.cover,w.create_time FROM activity_wish  aw LEFT JOIN user_wish w ON aw.id = w.wish_id " +
            "where user_id=#{userId} " +
            "and state_code=#{stateCode};")
    List<UserWishActivityListVo> userWishActivityList(Long userId, int stateCode);
}

